//
//  WlisTabBarC.swift
//  Swift_missScarlett
//
//  Created by xmg on 16/8/13.
//  Copyright © 2016年 wlis. All rights reserved.
//

import UIKit

class WlisTabBarC: UITabBarController {

    /** 单列 */
    static var token : dispatch_once_t = 0;
    override class func initialize(){
    
        dispatch_once(&token) { () -> Void in
            /** 设置标题 */
            let tabBarItem = UITabBarItem.appearance();
            /** 创建字典 */
            var attr  = Dictionary<String, AnyObject>();
            /** 设置颜色 */
            attr[NSForegroundColorAttributeName] = UIColor.blackColor();
            /** 设置按钮的选中状态 */
            tabBarItem.setTitleTextAttributes(attr, forState: .Selected);
            
            var attrNor = Dictionary<String, AnyObject>();
            /** 设置字体大小 */
            attrNor[NSFontAttributeName] = UIFont.systemFontOfSize(13);
            /** 设置字体 */
            tabBarItem.setTitleTextAttributes(attrNor, forState: .Normal);
            
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        /** 设置子控制器 */
        self.setUpAllChildVC();
        /** 设置子控制内容 */
        self.setUpAllTabBarBtn();
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

private extension WlisTabBarC{

    /** 设置标题内容 */
    func setUpAllTabBarBtn(){
        let nav = self.childViewControllers[0];
        nav.tabBarItem.title = "精华";
        nav.tabBarItem.image = UIImage(named: "tabBar_essence_icon")
        nav.tabBarItem.selectedImage = UIImage(named: "tabBar_essence_click_icon")?.imageWithRenderingMode(.AlwaysOriginal);
        
        let nav1 = self.childViewControllers[1];
        nav1.tabBarItem.title = "新帖";
        nav1.tabBarItem.image = UIImage(named: "tabBar_new_icon")
        nav1.tabBarItem.selectedImage = UIImage(named: "tabBar_new_click_icon")?.imageWithRenderingMode(.AlwaysOriginal);
        let nav2 = self.childViewControllers[2];
        nav2.tabBarItem.title = "关注";
        nav2.tabBarItem.image = UIImage(named:"tabBar_friendTrends_icon")
        nav2.tabBarItem.selectedImage = UIImage(named: "tabBar_friendTrends_click_icon")?.imageWithRenderingMode(.AlwaysOriginal);
        let nav3 = self.childViewControllers[3];
        nav3.tabBarItem.title = "我";
        nav3.tabBarItem.image = UIImage(named: "tabBar_me_icon")
        nav3.tabBarItem.selectedImage = UIImage(named: "tabBar_me_click_icon")?.imageWithRenderingMode(.AlwaysOriginal);
    }
    
    /** 设置所有子控制器 */
    func setUpAllChildVC(){
    
        /** 精华 */
        let essenceVc =  WlisEssenceVC();
        essenceVc.view.backgroundColor = UIColor.redColor();
        let essencenav = WlisNavigationC(rootViewController:essenceVc);
        addChildViewController(essencenav);
        /** 新帖 */
        let newVc = WlisNewVC();
        newVc.view.backgroundColor = UIColor.orangeColor();
        let newnav = WlisNavigationC(rootViewController: newVc);
        addChildViewController(newnav);
        /** 关注 */
        let friendVc = WlisFriendTrendsVC();
//        friendVc.view.backgroundColor = UIColor.blueColor();
        let friendnav = WlisNavigationC(rootViewController: friendVc);
        addChildViewController(friendnav);
        /** 我 */
        /** 加载  storyboard 控制器*/
        let storyboard = UIStoryboard(name: "WlisMeVC", bundle: nil)
        let meVc = storyboard.instantiateInitialViewController()!;
//        meVc.view.backgroundColor = UIColor.yellowColor();
        let menav = WlisNavigationC(rootViewController: meVc);
        addChildViewController(menav);
        
    }
}